package com.rq.base.ui;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.rq.base.reflect.activity.Act_onConfigurationChanged;
import com.rq.base.reflect.activity.Act_onLocalVoiceInteractionStarted;
import com.rq.base.reflect.activity.Act_onLocalVoiceInteractionStopped;
import com.rq.base.reflect.activity.Act_onLowMemory;
import com.rq.base.reflect.activity.Act_onMultiWindowModeChanged;
import com.rq.base.reflect.activity.Act_onNewIntent;
import com.rq.base.reflect.activity.Act_onPictureInPictureModeChanged;
import com.rq.base.reflect.activity.Act_onPreparePanel;
import com.rq.base.reflect.activity.Act_onResumeFragments;
import com.rq.base.reflect.activity.Act_onSaveInstanceState;
import com.rq.base.reflect.activity.Act_onStart;
import com.rq.base.reflect.activity.Act_onStop;
import com.rq.base.reflect.activity.Act_onTopResumedActivityChanged;
import com.rq.base.reflect.activity.Act_onTouchEvent;
import com.rq.base.reflect.activity.Act_onTrimMemory;
import com.rq.base.reflect.activity.Act_onWindowFocusChanged;

class ActivityLife extends FragmentActivity {

    protected Object getCtr() {
        return null;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (getCtr() instanceof Act_onNewIntent) {
            ((Act_onNewIntent) getCtr()).onNewIntent(intent);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (getCtr() instanceof Act_onStart) {
            ((Act_onStart) getCtr()).onStart();
        }
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (getCtr() instanceof Act_onConfigurationChanged) {
            ((Act_onConfigurationChanged) getCtr()).Act_onConfigurationChanged(newConfig);
        }
    }

    @Override
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode);
        if (getCtr() instanceof Act_onPictureInPictureModeChanged) {
            ((Act_onPictureInPictureModeChanged) getCtr()).onPictureInPictureModeChanged(isInPictureInPictureMode);
        }
    }

    @Override
    public void onTopResumedActivityChanged(boolean isTopResumedActivity) {
        super.onTopResumedActivityChanged(isTopResumedActivity);
        if (getCtr() instanceof Act_onTopResumedActivityChanged) {
            ((Act_onTopResumedActivityChanged) getCtr()).onTopResumedActivityChanged(isTopResumedActivity);
        }
    }

    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        if (getCtr() instanceof Act_onSaveInstanceState) {
            ((Act_onSaveInstanceState) getCtr()).onSaveInstanceState(outState);
        }
    }

    @Override
    public void onLocalVoiceInteractionStarted() {
        super.onLocalVoiceInteractionStarted();
        if (getCtr() instanceof Act_onLocalVoiceInteractionStarted) {
            ((Act_onLocalVoiceInteractionStarted) getCtr()).onLocalVoiceInteractionStarted();
        }
    }

    @Override
    public void onLocalVoiceInteractionStopped() {
        super.onLocalVoiceInteractionStopped();
        if (getCtr() instanceof Act_onLocalVoiceInteractionStopped) {
            ((Act_onLocalVoiceInteractionStopped) getCtr()).onLocalVoiceInteractionStopped();
        }
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        if (getCtr() instanceof Act_onResumeFragments) {
            ((Act_onResumeFragments) getCtr()).onResumeFragments();
        }
    }

    @Override
    public boolean onPreparePanel(int featureId, @Nullable View view, @NonNull Menu menu) {
        if (getCtr() instanceof Act_onPreparePanel && ((Act_onPreparePanel) getCtr()).onPreparePanel(featureId, view, menu)) {
            return true;
        }
        return super.onPreparePanel(featureId, view, menu);
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (getCtr() instanceof Act_onStop) {
            ((Act_onStop) getCtr()).onStop();
        }
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (getCtr() instanceof Act_onWindowFocusChanged) {
            ((Act_onWindowFocusChanged) getCtr()).onWindowFocusChanged(hasFocus);
        }
    }

    @Override
    public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
        super.onMultiWindowModeChanged(isInMultiWindowMode);
        if (getCtr() instanceof Act_onMultiWindowModeChanged) {
            ((Act_onMultiWindowModeChanged) getCtr()).onMultiWindowModeChanged(isInMultiWindowMode);
        }
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        if (getCtr() instanceof Act_onTrimMemory) {
            ((Act_onTrimMemory) getCtr()).onTrimMemory(level);
        }
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        if (getCtr() instanceof Act_onLowMemory) {
            ((Act_onLowMemory) getCtr()).onLowMemory();
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (getCtr() instanceof Act_onTouchEvent) {
            if (((Act_onTouchEvent) getCtr()).onTouchEvent(event)) {
                return true;
            }
        }

        return super.onTouchEvent(event);
    }
}
